#ifndef CARDITEM_H
#define CARDITEM_H

#include <QGraphicsObject>
#include <QPainter>
#include <QPropertyAnimation>
#include <QGraphicsSceneMouseEvent>
#include <QTimer>


class CardItem : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit CardItem(const QPixmap& pixmap,int a,int n, QGraphicsItem* parent = nullptr );

    QRectF boundingRect() const override
    {
        return m_pixmap.rect();
    }

    void paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) override
    {
        painter->drawPixmap(0, 0, m_pixmap);
    }
    bool m_isLifted = false;//用于判断是否处于准备出牌状态
    int ending;//代表花色和大小
    int n;//代表在数组中的第几个
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
private :
    void checkForCollision();
    void toggleLift();
    QPixmap m_pixmap;//存储图片
    QTimer* m_timer;
    bool m_isDragging = false;
    QPointF m_startPos;
    CardItem* m_itemToSwapWith = nullptr;
signals:
    void clicked(); // 点击信号
};

#endif // CARDITEM_H
